package com.kaigejava.template.hotdrink;

/**
 * Created by kaigejava on 2019/9/5.
 * 模板模式 三种方法都存在的
 */
public abstract class HotDrinkTemplate {
    public final void prepareRecipe(){
        boilWater();
        brew();
        pourInCup();
        //用于判断是否添加调料的
        if(wantCondimentsHook()){
            addCondiments();
        }
        send();
    }

    /**
     * 用于判断是否添加调料的。子类可以覆盖本方法
     * @return
     */
    protected  boolean wantCondimentsHook(){
        return true;
    }

    protected abstract void addCondiments();

    protected abstract void brew();

    private final void boilWater() {
        System.out.println("一.烧水");
    }
    private final void pourInCup() {
        System.out.println("三.倒入杯中");
    }
    private final void send() {
        System.out.println("五.送个客人");
    }
}
